package com.yonyou.pmclouds.billview.rmiimpl.buzi;

import com.yonyou.pmclouds.basecom.consts.BillTypeConst;
import com.yonyou.pmclouds.basecom.entity.PageObject;
import com.yonyou.pmclouds.basecom.entity.SuperVO;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.basecom.util.BeanHelper;
import com.yonyou.pmclouds.basecom.util.CommonFieldConst;
import com.yonyou.pmclouds.billview.entity.BillViewQueryVO;
import com.yonyou.pmclouds.billview.rmitf.IBillViewBuziService;
import com.yonyou.pmclouds.billview.util.BillViewUtil;
import com.yonyou.pmclouds.workConnect.entity.WorkConnectVO;
import com.yonyou.pmclouds.workConnect.service.rmiitf.WorkConnectQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class WorkConnectBuziServiceImpl implements IBillViewBuziService {

    @Autowired
    private WorkConnectQuery workConnectQuery;

    @Override
    public String getBillType() {
        return BillTypeConst.WORKCONNECT_BILLTYPE;
    }

    @Override
    public PageObject<Object> queryBillList(BillViewQueryVO billViewQueryVO) throws BusinessException {

        PageObject<Object> pageResult = workConnectQuery.queryByCondition(billViewQueryVO.getPkProject(),billViewQueryVO.getCreators(),billViewQueryVO.getStartTime(),
                billViewQueryVO.getEndTime(),billViewQueryVO.getBillStatus(),billViewQueryVO.getPageStart(),billViewQueryVO.getPageSize());

        setBillStatus(pageResult.getObjects());

        return pageResult;

    }

    @Override
    public SuperVO queryBillDetail(String pkBill) throws BusinessException {

        WorkConnectVO resultVO = workConnectQuery.selectOne(pkBill);
        setBillStatus(new WorkConnectVO[]{resultVO});
        BillViewUtil.setFormatDate(new WorkConnectVO[]{resultVO},new String[]{CommonFieldConst.CREATIONTIME},new String[]{"strCreationtime"});

        return resultVO;
    }

    private void setBillStatus(Object[] workConnectVOs){

        for (Object buziVO :
                workConnectVOs) {
            byte billStatus = (byte) BeanHelper.getProperty(buziVO, CommonFieldConst.BILLSTATUS);
            String strBillStatus = "";
            switch (billStatus){
                case 1 :
                    strBillStatus = "待接收";
                    break;
                case 2 :
                    strBillStatus = "已接收";
                    break;

                default:strBillStatus="";
            }
            BeanHelper.setProperty(buziVO,"strBillstatus",strBillStatus);
        }

    }
}
